<?php
if (!defined('IN_IA')) {
	exit('Access Denied');
}
class Welian_Indiana_Goods {
	function getGoods($id){
		global $_W;
		$condition =  "and uniacid = :uniacid";
		$params = array(':uniacid' => $_W['uniacid']);
		$sql = "SELECT * FROM " . tablename('weliam_indiana_goodslist') . " where 1 {$condition} and id='{$id}'";
		$goods = pdo_fetch($sql, $params);
		return $goods;
	}
	function getListByCategory($categoryid=0){
		global $_W;
		$condition =  "and uniacid = :uniacid";
		$params = array(':uniacid' => $_W['uniacid']);
		$sql = "SELECT * FROM " . tablename('weliam_indiana_goodslist') . " where 1 {$condition} and category_parentid='{$categoryid}' and status=2";
		$goodses = pdo_fetchall($sql, $params);
		return $goodses;
	}
	function getListBypcID($pid=0,$cid=0){
		global $_W;
		$condition =  "and uniacid = :uniacid";
		$params = array(':uniacid' => $_W['uniacid']);
		$sql = "SELECT * FROM " . tablename('weliam_indiana_goodslist') . " where 1 {$condition} and category_parentid='{$pid}' and category_childid='{$cid}' and status=2";
		$goodses = pdo_fetchall($sql, $params);
		return $goodses;
	}
	function getListByChildName($name=''){
		global $_W;
		$condition =  "and uniacid = :uniacid";
		$params = array(':uniacid' => $_W['uniacid']);
		$sql = "SELECT * FROM " . tablename('weliam_indiana_goodslist') . " where 1 {$condition}  and status=2";
		$goodses1 = pdo_fetchall($sql, $params);
		$goodses=array();
		foreach($goodses1 as $key=>$value){
			$category=m('category')->getCategoryByid($value['category_childid']);
			if($name==$category['name']){
				$goodses[$key]=$value;
			}

		}
		return $goodses;
	}
	function getListByPeriod_number($period_number = ''){
		//通过期号获取物品信息
		global $_W,$_GPC;
		$period = pdo_fetch("select * from".tablename('weliam_indiana_period')."where uniacid = '{$_W['uniacid']}' and period_number = '{$period_number}'");
		$goodslist = pdo_fetch("select init_money from".tablename('weliam_indiana_goodslist')."where uniacid = '{$_W['uniacid']}' and id = '{$period['goodsid']}' ");
		return $goodslist;
	}
}
